package com.biao.java8.starem_test;

import com.biao.java8.demo.pojo.Employee;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;

public class Test04_max_min {
    public static void main(String[] args) {
        List<Employee> listEmployee = new ArrayList<>();
        listEmployee.add(new Employee("abiu", 18, 8000d));
        listEmployee.add(new Employee("二狗", 24, 16000d));
        listEmployee.add(new Employee("黑狗哥", 27, 24000d));

        // stream求最大和最小元素
        Optional<Employee> maxEmployee = listEmployee.stream().max((a, b) -> a.getAge() - b.getAge());
        System.out.println("stream求最大和最小元素: --------------------------------");
        System.out.println(maxEmployee);
        // 换种写法
        Optional<Employee> minEmployee = listEmployee.stream().min(Comparator.comparingInt(Employee::getAge));
        System.out.println(minEmployee);
    }
}
